package com.scau.yangsuiyu.estore.controller;

import com.alibaba.fastjson.JSONObject;
import com.scau.yangsuiyu.estore.service.AppService;
import com.scau.yangsuiyu.estore.util.HibernateUtil;
import com.scau.yangsuiyu.estore.view.IndexView;
import de.felixroske.jfxsupport.FXMLController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.springframework.stereotype.Controller;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author suiyu_yang
 * @description 主界面的Controller类
 * @date 2019-04-23 17:59
 * @email suiyu_yang@163.com
 */
@FXMLController
public class MainStageController implements Initializable {
    @FXML
    private TabPane mainPane;


    /**
     * Called to initComboBoxes a controller after its root element has been
     * completely processed.
     *
     * @param location  The location used to resolve relative paths for the root object, or
     *                  <tt>null</tt> if the location is not known.
     * @param resources The resources used to localize the root object, or <tt>null</tt> if
     */
    public void initialize(URL location, ResourceBundle resources) {
        HibernateUtil.startHibernate();
        AppService.start(this);
        gotoIndexPage();
    }

    public void removeCurrentPage() {
        Tab selectedTab = mainPane.getSelectionModel().getSelectedItem();
        mainPane.getTabs().remove(selectedTab);
    }

    public void gotoNewPage(Tab tab) {
        mainPane.getTabs().add(tab);
        mainPane.getSelectionModel().select(tab);
    }

    public Tab getCurrentSelectedTab() {
        return mainPane.getSelectionModel().getSelectedItem();
    }

    private void gotoIndexPage() {
        new AppService().gotoIndexPage();
    }

}
